<?php

namespace App\Kuafu\User\Model;

use App\Kuafu\Base\Model\BaseModel;

class UserFirstLoginModel  extends BaseModel
{
    protected $table = 'user_first_login';
    public $timestamps = false;

    protected $fillable = ['userId', 'type', 'createdAt'];

    /**
     * 是否首次登录
     * @param int $userId
     * @param int $type
     * @return bool
     */
    public static function isUserFirstLogin(int $userId, int $type): bool
    {
        $userFirstLogin = self::query()->where('userId', $userId)->where('type', $type)->first();
        if ($userFirstLogin) {
            return false;
        }

        self::query()->create(['userId' => $userId, 'type' => $type, 'createdAt' => time()]);

        return true;
    }
}
